Apparatus and method for writing data to recording medium

ABSTRACT

A distance calculating unit calculates a distance from a current position on a tape to the end of the tape. A command processing unit receives a write command. If the distance is small, a determining unit sets a usable capacity of a buffer to be equal to a maximum capacity of the buffer. If the distance is large, the determining unit sets the usable capacity of the buffer according to the distance. If a capacity for data indicated by the write command is less than or equal to a difference between the usable capacity and current usage of the buffer, a buffer managing unit stores the data in the buffer. When the command processing unit receives a write FM command, the buffer managing unit reads the data from the buffer, updates the current usage, and a channel input/output unit writes the data to the tape.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention relates to an apparatus and a method for writingdata to a recording medium, and more particularly, to an apparatus and amethod for writing data in a buffer to a recording medium according to acommand from a higher-level device.

2. Background Information

A tape drive that writes data to a tape medium, such as a magnetic tape,is capable of returning a warning message to a host computer(hereinafter referred to as “host”) when the end of the tape mediumapproaches. In general, the tape drive temporarily stores data sent fromthe host in a buffer memory (hereinafter referred to as “buffer”) andwrites the data stored in the buffer to the tape medium withpredetermined timing. The tape drive is capable of returning a warningmessage to the host so that all the data stored in the buffer can bewritten to the tape medium.

There have been discussions about at which point on the tape medium awarning message should be issued. It is known in the prior art, that thenumber of data sets stored in the buffer memory is compared withinformation about a current writing position on the tape so as todetermine whether to inform the host of the logical end of tape (LEOT).Other prior art attempts include a technique wherein a recordingcapacity of an unrecorded area can be calculated as an amount of dataand a technique wherein a remaining capacity of a magnetic tape can bedetermined in consideration of a data compression ratio.

Accordingly, an object of the invention is allow data in a buffer to becompletely written to a recording medium while maintaining a high levelof recording efficiency on the recording medium.

SUMMARY OF THE INVENTION

In one embodiment, an apparatus for writing data in a buffer to arecording medium according to a command from a higher-level device. Theapparatus includes an identifying unit, a determining unit, and astorage unit. The identifying unit identifies a size of an unused areaof the recording medium. The determining unit determines, on the basisof the size of the unused area, an upper limit of a capacity for datathat can be stored in the buffer. The storage unit stores, according toa command for storing predetermined data in the buffer, thepredetermined data in the buffer on condition that the capacity for thedata in the buffer does not exceed the upper limit.

In another embodiment, a method for writing data in a buffer to arecording medium according to a command from a higher-level device. Themethod includes identifying a size of an unused area of the recordingmedium; determining, on the basis of the size of the unused area, anupper limit of a capacity for data that can be stored in the buffer; andstoring, according to a command for storing predetermined data in thebuffer, the predetermined data in the buffer on condition that thecapacity for the data in the buffer does not exceed the upper limit.

In a further embodiment, a program product for causing a computer tofunction as an apparatus that writes data in a buffer to a recordingmedium according to a command from a higher-level device. The programproduct causing the computer to function as a means for identifying asize of an unused area of the recording medium; a means for determining,on the basis of the size of the unused area, an upper limit of acapacity for data that can be stored in the buffer; and a means forstoring, according to a command for storing predetermined data in thebuffer, the predetermined data in the buffer on condition that thecapacity for the data in the buffer does not exceed the upper limit.

Other, advantages and embodiments of the invention will become apparentfrom the following detailed description, which, when taken inconjunction with the drawings, illustrate by way of example theprinciples of the invention.

BRIEF DESCRIPTION OF THE DRAWINGS

For a fuller understanding of the nature and advantages of theinvention, as well as a preferred mode of use, reference should be madeto the following detailed description read in conjunction with theaccompanying drawings, in which:

FIG. 1 is block diagram illustrating a configuration of a tape drive towhich an embodiment of the invention is applied;

FIG. 2 illustrates an overview of the embodiment of the invention;

FIG. 3 is a block diagram illustrating a functional configuration of acontroller according to an embodiment of the invention;

FIG. 4 illustrates an overview of an operation performed when anembodiment of a controller receives a write command; and

FIG. 5 is a flowchart illustrating an operation performed when anembodiment of a controller receives a write FM command.

DESCRIPTION OF THE PREFERRED EMBODIMENTS

The following description is made for the purpose of illustrating thegeneral principles of the invention and is not meant to limit theinventive concepts claimed herein. Further, particular featuresdescribed herein can be used in combination with other describedfeatures in each of the various possible combinations and permutations.

Unless otherwise specifically defined herein, all terms are to be giventheir broadest possible interpretation including meanings implied fromthe specification as well as meanings understood by those skilled in theart and/or as defined in dictionaries, treatises, etc.

It must also be noted that, as used in the specification and theappended claims, the singular forms “a”, “an”, and “the” include pluralreferents unless otherwise specified.

FIG. 1 is a block diagram illustrating a tape drive 10 that includes ahost interface (hereinafter referred to as “host I/F”) 11, a buffer 12,a channel 13, a head 14, and a motor 15. The tape drive 10 furtherincludes a controller 16, a head-position control system 17, and a motordriver 18.

A tape cartridge 20, which can be loaded by inserting it into the tapedrive 10, is also shown. The tape cartridge 20 includes a tape 23 woundon reels 21 and 22. As the reels 21 and 22 move, the tape 23 moves fromthe reel 21 to the reel 22 or from the reel 22 to the reel 21 in thelongitudinal direction. A magnetic tape illustrated as an example of thetape 23 may be replaced with another tape medium.

The host I/F 11 communicates with a host 30 serving as an example of ahigher-level device. For example, from the host 30, the host I/F 11receives a command (first command) for writing data to the tape 23, acommand (second command) for moving the tape 23 to a target position,and a command (third command) for reading data from the tape 23. Thehost I/F 11 uses a communication standard, such as the Small ComputerSystem Interface (SCSI). In the SCSI, a Write command corresponds to thefirst command, a Locate command or a Space command corresponds to thesecond command, and a Read command corresponds to the third command. Thehost I/F 11 returns, to the host 30, a response indicating whether theprocess corresponding to the received command has succeeded.

The buffer 12 is a memory that stores data to be written to the tape 23or data read from the tape 23. For example, the buffer 12 is a dynamicrandom access memory (DRAM). The buffer 12 includes a plurality ofbuffer segments, each storing a data set serving as a unit of readingand writing with respect to the tape 23.

The channel 13 is a communication path through which data to be writtento the tape 23 is sent to the head 14 or through which data read fromthe tape 23 is received from the head 14. During movement of the tape 23in the longitudinal direction, the head 14 writes information to thetape 23 or reads information from the tape 23. The motor 15 causes thereels 21 and 22 to rotate. Although the motor 15 is represented by asingle rectangular shape in FIG. 1, it is preferable to provide onemotor 15 for each of the reels 21 and 22 (i.e., two motors 15 in total).

The controller 16 controls the overall operation of the tape drive 10.For example, according to a command received by the host I/F 11, thecontroller 16 controls writing of data to or reading of data from thetape 23. The controller 16 also controls the operation of thehead-position control system 17 and the motor driver 18.

The head-position control system 17 is a system that tracks one or aplurality of desired wraps. Here, a wrap means a group of a plurality oftracks on the tape 23. When the need for switching a wrap arises, theneed for electrically switching the head 14 also arises. Such aswitching operation is controlled by the head-position control system17.

The motor driver 18 drives the motor 15. If two motors 15 are providedas described above, two motor drivers 18 are provided here. If the tapedrive 10 of FIG. 1 is an enterprise tape drive TS1120 from IBM in theUS, data is written to the tape 23 on a data set basis by the tape drive10. The data set size is constant.

A distance between adjacent data sets or a distance between the end ofone data set and the end of the next data set needs to be within 4 m,due to specification constraints. An ideal distance between adjacentdata sets varies depending on the generation, but is about 10 cm in aformat for the second-generation enterprise tape drive. If no erroroccurs, an actual distance between adjacent data sets substantiallyagrees with the ideal distance.

However, if an error occurs during data writing, since data rewriting isperformed up to three times, an actual distance between adjacent datasets may be three times that in normal cases. Moreover, if data cannotbe written even when the distance between adjacent data sets is threetimes that in normal cases, or if data writing is interrupted due to aservo error or the like, the tape drive 10 changes the writing positionas necessary so as to try to perform data rewriting. Therefore, theactual distance between adjacent data sets may even be up to 4 m.

At the same time, when the end of the tape 23 approaches during datawriting, the tape drive 10 returns a warning message “Early Warning” tothe host 30 so that all the data stored in the buffer 12 can be writtento the tape 23. In this case, to ensure that all the data stored in thebuffer 12 can be written to the tape 23, it is necessary to return thewarning message at a position (4×N) m or more from the end of the tape23, where N is the maximum number of data sets that can be stored in thebuffer 12. This is because it is possible, as described above, that upto 4 m may be required per data set.

The second-generation enterprise tape drive allows 256 data sets to bestored in the buffer 12. Therefore, if the calculation described aboveis applied here, the tape drive 10 starts returning the warning messageat a position about 1000 m from the end of the tape 23. In the TS1120,the tape 23 is about 600 m in length. To ensure that data can be writtento the tape 23 until a specified capacity is reached, the tape 23reciprocates or moves back and forth 28 times. In other words, the tape23 moves from one reel to another 56 times. Thus, data is written to thetape 23 over a total length of 33600 m, and “1000 m” described above isequivalent to about 3% of the total length. This has a significantimpact, particularly in the tape drive 10 having the buffer 12 of largesize.

The tape 23 has about 7% room for preventing the capacity from beingaffected by an error during writing. However, if 3% of the total lengthis devoted to the warning message “Early Warning”, it is possible thatdata cannot be written until a specified capacity is reached if the tapedrive 10 is not in very good working order. Therefore, it is notrealistic to start returning “Early Warning” at a position as much as1000 m from the end of the tape 23 to control the writing operationperformed by the host 30.

To avoid impacts on the capacity, the tape drive 10 is configured tostart returning the warning message “Early Warning” to the host 30 uponreaching a position (L×2×N+4) m from the end of the tape 23, where L isan ideal length (m). Therefore, if data is written to a portion near theend of the tape 23 by the tape drive 10 which always requires, for adata writing operation, a length nearly three times that required innormal cases, data in the buffer 12 cannot be completely written to thetape 23.

Thus, in the embodiment, usage of the buffer 12 (i.e., capacity for datain the buffer 12) is limited near the end of the tape 23. This makes itpossible to always ensure that all the data in the buffer 12 is writtento the tape 23. That is, an upper limit of the amount of use of thebuffer 12 is defined by a conditional branch expression as follows:if (N<X/4−1)n=Nelsen=X/4−1

where n is an upper limit of the amount of use of the buffer 12(hereinafter referred to as “usable capacity”), X (m) is a distance froma current position on the tape 23 to the end of the tape 23, and N isthe amount of use of the buffer 12 in which data is stored up to thecapacity of the buffer 12 (hereinafter referred to as “maximumcapacity”). Here, the usable capacity n and the maximum capacity N arerepresented by the number of data sets. This conditional branchexpression will now be explained with reference to FIG. 2.

FIG. 2 illustrates how the buffer 12 is used in the embodiment. FIG. 2(a) illustrates the case of “N<X/4−1” which is a condition of the “if”statement in the conditional branch expression described above. Thiscondition can be converted to a condition with respect to the variable Xas follows: “X>4(N+1)”. That is, if the distance X from the currentposition on the tape 23 to the end of the tape 23 is greater than4(N+1), the maximum capacity N of the buffer 12 is set as the usablecapacity n of the buffer 12.

FIG. 2( b) illustrates the case of “N≧X/4−1” which is a condition of the“else” statement in the conditional branch expression described above.This condition can be converted to a condition with respect to thevariable X as follows: “X≦4(N+1)”. That is, if the distance X from thecurrent position on the tape 23 to the end of the tape 23 is less thanor equal to 4(N+1), (X/4−1) is set as the usable capacity n of thebuffer 12.

In FIG. 2( a) and FIG. 2( b), a thick line in the buffer 12 indicates ausable part of the buffer 12. Next, the controller 16 that realizes theforegoing operation will be described. Here, SCSI commands will bedescribed as examples of commands in the embodiment.

FIG. 3 is a block diagram illustrating a functional configuration of thecontroller 16 that includes a command processing unit 41, a buffermanaging unit 42, a channel input/output unit 43, a distance calculatingunit 44, a usable-capacity determining unit 45, a usable-capacitystorage unit 46, and a current-usage storage unit 47. The commandprocessing unit 41 receives a command from the host I/F 11. Examples ofthe command include a Write command for storing data in the buffer 12and a Write FileMark (Write FM) command for writing data stored in thebuffer 12 to the tape 23.

When the command processing unit 41 receives a Write command, the buffermanaging unit 42 directs the usable-capacity determining unit 45 todetermine a usable capacity of the buffer 12. Then, on the basis of theusable capacity stored in the usable-capacity storage unit 46 and theamount of data currently stored in the buffer 12, the amount beingstored in the current-usage storage unit 47 (hereinafter referred to as“current usage”), the buffer managing unit 42 determines whether dataindicated by the Write command is to be stored in the buffer 12. Whenthe command processing unit 41 receives a Write FM command, the buffermanaging unit 42 reads data from the buffer 12, passes the read data tothe channel input/output unit 43, and subtracts the amount of the readdata from the current usage stored in the current-usage storage unit 47.In the present embodiment, the buffer managing unit 42 is provided as anexample of a storage unit that stores predetermined data in a buffer.

The channel input/output unit 43 outputs, to the channel 13, data readfrom the buffer 12 by the buffer managing unit 42. Also, the channelinput/output unit 43 stores, in the buffer 12, data received from thechannel 13. The distance calculating unit 44 obtains, via the channel13, information about a current position on the tape 23. The currentposition is read, through tracking of a servo track, by a servo headserving as the head 14. The distance calculating unit 44 calculates adistance to the end of the tape 23 by using information about thelocation of the end of the tape 23, the information being stored inadvance. In the present embodiment, the distance calculating unit 44 isprovided as an example of an identifying unit that identifies the sizeof an unused area.

The usable-capacity determining unit 45 determines a usable capacity ofthe buffer 12 on the basis of the distance calculated by the distancecalculating unit 44 and a maximum capacity of the buffer 12, the maximumcapacity being stored in advance. In the present embodiment, theusable-capacity determining unit 45 is provided as an example of adetermining unit that determines an upper limit of a capacity for datathat can be stored in the buffer 12.

The usable-capacity storage unit 46 stores the usable capacitydetermined by the usable-capacity determining unit 45. The current-usagestorage unit 47 stores current usage that is the amount of datacurrently stored in the buffer 12.

The operations performed by the controller 16 include a first operationthat involves receiving data from the host 30 and storing the receiveddata in the buffer 12, and a second operation that involves reading thedata stored in the buffer 12 and writing the read data to the tape 23.These operations will now be individually described. The first operationis performed when a Write command is received from the host 30.Therefore, the first operation will be described as an operationperformed when the controller 16 receives a Write command. The secondoperation is performed, for example, when a Write FM command is receivedfrom the host 30 or when the amount of data in the buffer 12 reaches apredetermined level. Here, the second operation will be described as anoperation performed when the controller 16 receives a Write FM command.

FIG. 4 is a flowchart illustrating an operation performed by thecontroller 16 when a Write command is received. This operation isperformed on condition that the distance calculating unit 44 obtainsfrom the channel 13 a current position on the tape 23, subtracts thecurrent position from the end position of the tape 23 to determine adistance X (m) from the current position to the end of the tape 23, andholds the distance X. Here, the end position can be obtained, forexample, from a cartridge memory in the tape cartridge 20 when the tapecartridge 20 is loaded.

In the controller 16, first, the command processing unit 41 receives aWrite command and informs the buffer managing unit 42 of the receipt ofthe Write command (step S401). Then, the buffer managing unit 42 directsthe usable-capacity determining unit 45 to determine a usable capacityof the buffer 12. Thus, the usable-capacity determining unit 45determines whether the distance to the end of the tape 23 reaches athreshold at which the usable capacity of the buffer 12 needs to bechanged.

In other words, the usable-capacity determining unit 45 determineswhether the condition “N<X/4−1” is satisfied, where N is the maximumcapacity of the buffer 12 and X (m) is the distance from the currentposition to the end of the tape 23 (step S402). As described above,since the distance calculating unit 44 holds the distance X (m), theusable-capacity determining unit 45 obtains the distance X from thedistance calculating unit 44. At the same time, since N is the capacityof the buffer 12, a value held in advance can be used. The maximum tapelength “4 m” required for one data set is also a value held in advanceand can be used.

As a result, if the condition “N<X/4−1” is satisfied, theusable-capacity determining unit 45 sets the maximum capacity N of thebuffer 12 as the usable capacity n (step S403). That is, the maximumcapacity N is stored in the usable-capacity storage unit 46 as theusable capacity n. On the other hand, if the condition “N<X/4−1” is notsatisfied, the usable-capacity determining unit 45 sets (X/4−1) as theusable capacity n. That is, (X/4−1) is stored in the usable-capacitystorage unit 46 as the usable capacity n.

Next, the buffer managing unit 42 determines whether there is free spacein the buffer 12 (step S405). Specifically, the buffer managing unit 42subtracts current usage stored in the current-usage storage unit 47 fromthe usable capacity stored in the usable-capacity storage unit 46 so asto determine a difference therebetween. Then, the buffer managing unit42 determines whether a capacity for data stored in the buffer 12according to the Write command is less than or equal to the difference.

If there is free space in the buffer 12, that is, if the capacity fordata in the buffer 12 is less than or equal to the difference, thebuffer managing unit 42 obtains data received together with the Writecommand by the command processing unit 41 and stores the obtained datain the buffer 12 (step S406). Next, the buffer managing unit 42 adds thecapacity for data stored in the buffer 12 to the current usage stored inthe current-usage storage unit 47 (step S407). Then, the buffer managingunit 42 informs the command processing unit 41 of completion of theWrite command, and thus the command processing unit 41 informs the host30 of the completion of the Write command (step S408).

On the other hand, if there is no free space in the buffer 12, that is,if the capacity for data in the buffer 12 exceeds the differencedescribed above, the buffer managing unit 42 informs the commandprocessing unit 41 of this. Then, the command processing unit 41 informsthe host 30 of a buffer full condition and causes the host 30 to wait(step S409).

FIG. 5 is a flowchart illustrating an operation performed by thecontroller 16 when a Write FM command is received. In the controller 16,first, the command processing unit 41 receives a Write FM command andinforms the buffer managing unit 42 of the receipt of the Write FMcommand (step S421). Then, the buffer managing unit 42 reads data storedin the buffer 12 and passes the read data to the channel input/outputunit 43 (step S422). At the same time, the buffer managing unit 42subtracts the capacity for the read data from current usage stored inthe current-usage storage unit 47 (step S423). For example, when alldata stored in the buffer 12 is read and written to the tape 23 inresponse to the Write FM command, the current usage stored in thecurrent-usage storage unit 47 is cleared to “0”.

Next, the channel input/output unit 43 outputs, to the channel 13, thedata received from the buffer managing unit 42 so that the data can bewritten to the tape 23 (step S424). Then, the channel input/output unit43 informs the command processing unit 41 of completion of the Write FMcommand, and the command processing unit 41 informs the host 30 of thecompletion of the Write FM command (step S425).

In the embodiment described above, a value set as the usable capacity nis changed depending on whether the condition “N<X/4−1” is satisfied,and if this condition is not satisfied, the usable capacity n is set to“X/4−1”. However, this is only an example. That is, the foregoingcondition may be “X (m)>N×4 (m)” (i.e., a distance to the end of thetape 23 is greater than a value obtained by multiplying the maximumcapacity N of the buffer 12 by 4 (m)) and if this condition is notsatisfied, the usable capacity n of the buffer 12 may be set to “X (m)/4(m)” (i.e., a value obtained by dividing the distance to the end of thetape 23 by 4 (m)).

The foregoing condition and the value that is set as the usable capacitywhen the condition is not satisfied may be generalized as follows. Thatis, the condition may be “a distance to the end of the tape 23 exceeds apredetermined threshold”. Here, the predetermined threshold may be anyvalue that is determined on the basis of the number of data setscorresponding to the capacity of the buffer 12 and a tape lengthrequired for recording one data set.

The value that is set as the usable capacity when the condition is notsatisfied may be any value that is the number of data sets correspondingto a capacity smaller than the capacity of the buffer 12. However, forhigher recording efficiency on the tape 23, it is desirable that theusable capacity of the buffer 12 decrease as the distance to the end ofthe tape 23 decreases. Alternatively, the value that is set as theusable capacity when the condition is not satisfied may be determinedaccording to the distance to the end of the tape 23. It is furtherdesirable to determine the value on the basis of the distance to the endof the tape 23 and a tape length required for recording one data set.

As described above, the embodiment is configured such that the buffer 12is fully used while there is a sufficient distance to the end of thetape 23, but such that an upper limit of the amount of use of the buffer12 gradually decreases as the distance to the end of the tape 23decreases. Thus, in the present embodiment, it is possible to preventdata in the buffer from not being completely written to the recordingmedium while maintaining a high level of recording efficiency on therecording medium.

With this configuration, when “Early Warning” is issued or X=L×2×N+4 issatisfied, n=12 is obtained in the second-generation enterprise tapedrive where L=0.1 (m) and N=256. That is, since the usable capacity ofthe buffer 12 is one-twentieth the capacity of the buffer 12, the tapedrive 10 cannot benefit from the buffer 12 in terms of performance.

However, this does not pose a specific problem, for reasons describedbelow. First, it is unusual that “Early Warning” is actually issued, anddata can be written to the tape 23 up to a specified capacity normallywhile “N<X/4−1” is satisfied. Second, for example, in a drive which isin poor condition and takes nearly three times longer than the timetypically required to write data to the tape 23, even if the buffer 12is fully used, performance achieved is only about one-third that of adrive in good condition, and thus, the size of the buffer 12 does notcreate a bottleneck.

The technique described above is applicable not only to the tape drive10 of FIG. 1, but also to other storage devices, such as a hard diskdrive (HDD) that uses a different segment when data cannot be written toa given area. When the technique described above is applied to anotherstorage device, the usable capacity of the buffer 12 will be determinednot on the basis of the distance to the end of the recording medium, buton the basis of the size of an unused area of the recording medium.

The invention may be implemented by hardware, software, or a combinationof both. Also, the invention may be embodied as a computer, a dataprocessing system, or a computer program, which can be stored on acomputer-readable medium and distributed. The medium may be anelectronic, magnetic, optical, electromagnetic, infrared, orsemiconductor system (or device or apparatus) or a propagation medium.Examples of the computer-readable medium include a semiconductor orsolid-state storage device, a magnetic tape, a removable computerdiskette, a random-access memory (RAM), a read-only memory (ROM), arigid magnetic disk, and an optical disk. Examples of currentlyavailable optical disks include a compact-disk read-only memory(CD-ROM), a compact disk read/write (CD-R/W), and a digital versatiledisk (DVD).

Those skilled in the art will appreciate that various adaptations andmodifications of the just-described preferred embodiments can beconfigured without departing from the scope and spirit of the invention.Therefore, it is to be understood that, within the scope of the appendedclaims, the invention may be practiced other than as specificallydescribed herein.

What is claimed is:
 1. An apparatus for writing data in a buffer to arecording medium according to a command from a higher-level device, theapparatus comprising: an identifying unit configured to identify a sizeof an unused area of the recording medium; a determining unit configuredto determine, on the basis of the size of the unused area, an upperlimit of a capacity for data that can be stored in the buffer; and astorage unit configured to store, according to a command for storingpredetermined data in the buffer, the predetermined data in the bufferon condition that the capacity for data in the buffer does not exceedthe upper limit, wherein the predetermined data in the buffer includes aplurality of data sets, wherein the determining unit is configured todetermine the number of data sets corresponding to a capacity of thebuffer as the upper limit when the size of the unused area exceeds apredetermined threshold, wherein the determining unit is configured todetermine the number of data sets corresponding to a capacity smallerthan the capacity of the buffer as the upper limit when the size of theunused area is less than or equal to the predetermined threshold,wherein the determining unit determines the upper limit using a branchexpression:if (NX/4−1), n=Nelse n=X/4−1, wherein is the number of data sets corresponding to thecapacity of the buffer as the upper limit, X represents the size of theunused area of the recording medium, and N represents the number of datasets corresponding to a maximum capacity of the buffer.
 2. The apparatusaccording to claim 1, wherein if the size of the unused area exceeds apredetermined threshold, the determining unit determines a capacity ofthe buffer as the upper limit, while if the size of the unused area isless than or equal to the predetermined threshold, the determining unitdetermines a capacity smaller than the capacity of the buffer as theupper limit.
 3. The apparatus according to claim 2, wherein if the sizeof the unused area is less than or equal to the predetermined threshold,the determining unit determines the upper limit such that the upperlimit decreases as the unused area decreases.
 4. The apparatus accordingto claim 1, wherein when the size of the unused area is less than orequal to the predetermined threshold, the determining unit determinesthe number of data sets corresponding to the size of the unused area asthe number of data sets corresponding to the capacity smaller than thecapacity of the butler.
 5. The apparatus according to claim 4, whereinif the size of the unused area is less than or equal to thepredetermined threshold, the determining unit determines the number ofdata sets corresponding to the size of the unused area on the basis ofthe size of the unused area and a size determined in advance as a sizeof an area required for recording one data set.
 6. The apparatusaccording to claim 1, wherein the determining unit determines thepredetermined threshold on the basis of the number of data setscorresponding to the capacity of the buffer and a size determined inadvance as a size of an area required for recording one data set.
 7. Theapparatus according to claim 1, wherein the predetermined data includesa plurality of data sets; and the storage unit stores the predetermineddata in the buffer if the number of data sets included in thepredetermined data does not exceed a difference between the number ofdata sets corresponding to the upper limit and the number of data setsstored in the buffer.
 8. The apparatus according to claim 1, wherein therecording medium is a tape medium; and the identifying unit identifies adistance from a current position on the tape medium to the end of thetape medium as the size of the unused area.
 9. The apparatus accordingto claim 1, wherein the plurality of data sets each have a same size.10. The apparatus according to claim 9, wherein the determining unitdetermines the predetermined threshold on the basis of the number ofdata sets corresponding to the capacity of the buffer and a sizedetermined in advance as a size of an area required for recording onedata set.
 11. The apparatus according to claim 1, wherein the pluralityof data sets each have a same size.
 12. The apparatus according to claim11, wherein the determining unit determines the predetermined thresholdon the basis of the number of data sets corresponding to the capacity ofthe buffer and a size determined in advance as a size of an arearequired for recording one data set.
 13. A method for writing data in abuffer to a recording medium according to a command from a higher-leveldevice, the method comprising the steps of: identifying a size of anunused area of the recording medium; determining, on the basis of thesize of the unused area, an upper limit of a capacity for data that canbe stored in the buffer using a branch expression:if (N<X/4−1), n=N;else n=X/4−1, where n corresponding to the capacity of the buffer as theupper limit, X represents the size of the unused area of the recordingmedium, and N represents a maximum capacity of the buffer; and storing,according to a command for storing predetermined data in the buffer, thepredetermined data in the buffer on condition that the capacity for datain the buffer does not exceed the upper limit.
 14. A program productembodied on a non-transitory computer-readable medium for causing acomputer to function as an apparatus that writes data in a buffer to arecording medium according to a command from a higher-level device, theprogram product causing the computer to function as: means foridentifying a size of an unused area of the recording medium; means fordetermining, on the basis of the size of the unused area, an upper limitof a capacity for data that can be stored in the buffer; and means forstoring, according to a command for storing predetermined data in thebuffer, the predetermined data in the buffer on condition that thecapacity for data in the buffer does not exceed the upper limit, whereinthe predetermined data in the buffer includes a plurality of data sets,wherein the means for determining is configured to determine the numberof data sets corresponding to a capacity of the buffer as the upperlimit when the size of the unused area exceeds a predeterminedthreshold, wherein the means for determining is configured to determinethe number of data sets corresponding to a capacity smaller than thecapacity of the buffer as the upper limit when the size of the unusedarea is less than or equal to the predetermined threshold, wherein themeans for determining determines the upper limit using a branchexpression:if (N<X/4−1), n=N;else n=X/4−1, where n is the number of data sets corresponding to thecapacity of the buffer as the upper limit, X represents the size of theunused area of the recording medium, and N represents the number of datasets corresponding to a maximum capacity of the buffer.